package com.asf.sofom.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.asf.sofom.domain.OGenero;

@Repository(value="generoDao")
public class JPAGenero implements GeneroDao{

	private EntityManager em = null;
	
	@PersistenceContext
	public void setEntityManager(EntityManager em){
		this.em = em;
	}	
	
	@Transactional(readOnly = true)
	@SuppressWarnings("unchecked")
	public List<OGenero> getGenero() {
		TypedQuery<OGenero> tq = (TypedQuery<OGenero>) em.createNativeQuery("Select * from personas_genero", OGenero.class);
		List<OGenero> lg = tq.getResultList();
		return lg;
	}

	@Transactional(readOnly = false)
	public void setGenero(List<OGenero> genero) {
		em.merge(genero);
	}

}
